Conditions | 9 |
Paths | 48 |
Total Lines | 87 |
Lines | 87 |
Ratio | 100 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
41 | View Code Duplication | objects.on('expand.drawer', function expand(event, speed, stay) { |
|
|
|||
42 | var drawer = $(this), |
||
43 | position = drawer.data('position'), |
||
44 | buttons = $('.button.drawer'), |
||
45 | button = buttons.filter('[href="#' + drawer.attr('id') + '"]'), |
||
46 | samePositionButtons = buttons.filter('.' + position), |
||
47 | context = drawer.data('context') ? '.' + drawer.data('context') : '', |
||
48 | height = getHeight(); |
||
49 | |||
50 | drawer.trigger('expandstart.drawer'); |
||
51 | |||
52 | speed = (typeof speed === 'undefined' ? settings.speed : speed); |
||
53 | stay = (typeof stay === 'undefined' ? false : true); |
||
54 | |||
55 | // update button state |
||
56 | samePositionButtons.removeClass('selected'); |
||
57 | |||
58 | // Close opened drawers from same region |
||
59 | $('.drawer.' + position).filter(function() { |
||
60 | return $(this).data('open'); |
||
61 | }).trigger('collapse.drawer', [speed, true]); |
||
62 | |||
63 | if (position === 'vertical-left') { |
||
64 | drawer.css({ |
||
65 | width: 0, |
||
66 | height: height, |
||
67 | display: 'block' |
||
68 | }) |
||
69 | .animate({ |
||
70 | width: settings.verticalWidth |
||
71 | }, { |
||
72 | duration: speed, |
||
73 | step: function(now){ |
||
74 | form.css('margin-left', now + 1); // +1px right border |
||
75 | }, |
||
76 | complete: function() { |
||
77 | form.css('margin-left', settings.verticalWidth + 1); // +1px right border |
||
78 | drawer.trigger('expandstop.drawer'); |
||
79 | } |
||
80 | }); |
||
81 | } |
||
82 | else if (position === 'vertical-right') { |
||
83 | drawer.css({ |
||
84 | width: 0, |
||
85 | height: height, |
||
86 | display: 'block' |
||
87 | }) |
||
88 | .animate({ |
||
89 | width: settings.verticalWidth |
||
90 | }, { |
||
91 | duration: speed, |
||
92 | step: function(now){ |
||
93 | form.css('margin-right', now + 1); // +1px left border |
||
94 | }, |
||
95 | complete: function() { |
||
96 | form.css('margin-right', settings.verticalWidth + 1); // +1px right border |
||
97 | drawer.trigger('expandstop.drawer'); |
||
98 | } |
||
99 | }); |
||
100 | } |
||
101 | else if (position === 'horizontal') { |
||
102 | drawer.animate({ |
||
103 | height: 'show' |
||
104 | }, { |
||
105 | duration: speed, |
||
106 | complete: function() { |
||
107 | drawer.trigger('expandstop.drawer'); |
||
108 | } |
||
109 | }); |
||
110 | } |
||
111 | |||
112 | button.addClass('selected'); |
||
113 | |||
114 | // store state |
||
115 | if(Symphony.Support.localStorage === true) { |
||
116 | // Put in a try/catch incase we exceed storage space |
||
117 | try { |
||
118 | window.localStorage['symphony.drawer.' + drawer.attr('id') + context] = 'opened'; |
||
119 | } |
||
120 | catch(e) { |
||
121 | window.onerror(e.message); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | wrapper.addClass('drawer-' + position); |
||
126 | drawer.data('open', true); |
||
127 | }); |
||
128 | |||
268 |